<template>
  <div class="app-container">
    <u-page title="升级日志">
      <u-filtered>
        <el-form :inline="true" :model="listQuery" class="search-form">
          <el-form-item label="类型" prop="upgrade">
            <el-select v-model="listQuery.upgrade" placeholder="请选择类型" class="disabled" clearable>
              <el-option v-for="item in upgradeList" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="卡号" prop="memberId">
            <el-input v-model="listQuery.memberId" placeholder="请输入卡号" clearable style="width: 170px" />
          </el-form-item>
          <el-form-item label="手机号" prop="mobile">
            <el-input v-model="listQuery.mobile" placeholder="请输入会员手机号" clearable style="width: 170px" />
          </el-form-item>
          <el-form-item label="状态" class="ack">
            <el-select v-model="listQuery.ack" placeholder="状态" clearable>
              <el-option label="全部" value="" />
              <el-option label="待执行" value="0" />
              <el-option label="成功" value="1" />
              <el-option label="失败" value="2" />
            </el-select>
          </el-form-item>
          <el-form-item label="操作时间" prop="searchDate">
            <u-date-time-picker v-model="daterange" @change="changeDate" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="hdlFilter">搜索</el-button>
          </el-form-item>
        </el-form>
      </u-filtered>
      <u-table
        :data="list"
        :loading="listLoading"
        :options="listOptions"
        :columns="columns"
        :pagination.sync="listQuery"
        :fetch="hdlList"
        @selection-change="hdlSelectChange"
      >
      </u-table>
    </u-page>
  </div>
</template>

<script>
export default {
  data() {
    return {
      api: this.$u.api.PluginsUpgradenoticeLog,
      daterange: [],
      orderShow: false,
      listQuery: {
        page: 1,
        pageSize: 10,
        totalCount: 1,
        beginTime: '',
        endTime: ''
      },
      // 表格
      columns: [
        {
          prop: 'upgrade',
          label: '类型',
          render: (h, params) => {
            if (params.row.upgrade === 1) {
              return h('el-tag', { props: { type: 'success' }}, '升级')
            } else {
              return h('el-tag', { props: { type: 'error' }}, '降级')
            }
          }
        },
        {
          prop: 'memberId',
          label: '会员卡号'
        },
        {
          prop: 'mobile',
          label: '手机号'
        },
        {
          prop: 'upgradeDate',
          label: '升级日期'
        },
        {
          prop: 'amount',
          label: '消费金额'
        },
        {
          prop: 'originalLevelName',
          label: '原始等级'
        },
        {
          prop: 'targetLevelName',
          label: '目标等级'
        },
        {
          prop: 'ack',
          label: '执行结果',
          render: (h, params) => {
            if (params.row.ack === 1) {
              return h('el-tag', { props: { type: 'success' }}, '成功')
            } else {
              return h('el-tag', { props: { type: 'error' }}, '失败')
            }
          }
        },
        {
          prop: 'createdAt',
          label: '操作时间',
          timestamp: true
        }
      ],
      upgradeList: [
        {
          value: '',
          label: '全部'
        },
        {
          value: '1',
          label: '升级'
        }, {
          value: '0',
          label: '降级'
        }
      ],
      listLoading: false,
      list: [],
      orderList: [],
      listOptions: {
        stripe: true
      }
    }
  },
  created() {
    this.hdlList()
  },
  methods: {
    changeDate(item) {
      if (item) {
        this.listQuery.beginTime = item[0]
        this.listQuery.endTime = item[1]
      } else {
        this.listQuery.beginTime = ''
        this.listQuery.endTime = ''
      }
    }

  }
}
</script>

<style scoped>

</style>
